"""
演示序列的切片操作
"""
# 对列表进行切片，从1开始，4结束，步长为1
my_list = [0,1,2,3,4,5,6,7,8]
list2 = my_list[1:4] # 步长默认是1，可以省略
print(f"结果1：{list2}")

# 对元组进行切片，从头开始到最后结束，步长1
my_tuple = (0,1,2,3,4,5,6,7)
tuple2 = my_tuple[:]
print(f"结果2：{tuple2}")

# 对字符串进行切片,从头开始，到最后结束，步长2
my_str = '01234567'
str2 = my_str[::2]
print(f"结果3：{str2}")

# 对字符串进行切片，从头开始，到最后结束，步长-1
my_str = '01234567'
str3 = my_str[::-1]  # 等同于将序列反转
print(f"结果4：{str3}")

# 对列表进行切片，从3开始，到1结束，步长-1
my_list = [0,1,2,3,4,5,6,7,8]
list3 = my_list[3:1:-1]
print(f"结果5：{list3}")

# 对元组进行切片，从头开始，到为结束，步长-2
my_tuple = (0,1,2,3,4,5,6,7)
tuple3 = my_tuple[::-2]
print(f"结果6：{tuple3}")
